package com.example.demo2.mapper;

import com.example.demo2.entity.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface StandardMapper {
    @Select("select * from standard where staId=#{staId}")
    Standard findStandardByStaId(@Param("staId") Integer staId);

    @Select("select * from standard where staName like #{query} or staGB like #{query}")
    public List<Standard> searchStandard(@Param("query") String query);

    @Select("select * from standard")
    public List<Standard> findAllStandard();


    @Insert("insert into standard (staName,staType,staGB) values(#{Standard.staName},#{Standard.staType},#{Standard.staGB})" )
    public int AddOneStandard(@Param("Standard") Standard Sd);

    @Delete("delete from standard where staId = #{staId}")
    public int DeleteOneStandard(@Param("staId") int staId);
    @Insert({
            "<script>",
            "INSERT INTO standard(staName, staType, staGB) VALUES ",
            "<foreach collection='standards' item='standard' separator=','>",
            "(#{standard.staName}, #{standard.staType}, #{standard.staGB})",
            "</foreach>",
            "</script>"
    })
    int insertStandardList(@Param("standards") List<Standard> standards);

}
